package cn.tedu._02notice.base.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 统一响应结果类
 */
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    private Integer state;
    private String message;
    private Object data;


    /**
     * 1、构造方法:针对于没有具体数据返回的控制器方法,比如:添加资讯、删除资讯、更新资讯;
     * @param statusCode
     */
    public JsonResult(StatusCode statusCode) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
    }

    /**
     * 2、构造方法:针对于有具体数据返回的控制器方法,比如:资讯列表、资讯详情
     */
    public JsonResult(StatusCode statusCode, Object data) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
        this.data = data;
    }


    public static JsonResult ok() {
        return new JsonResult(StatusCode.OPERATION_SUCCESS);
    }

    public static JsonResult ok(Object data) {
        return new JsonResult(StatusCode.OPERATION_SUCCESS, data);
    }
}
